Skip to content

fix: mark IpPrefix::isValid() as const#1213

Open
xq9mend wants to merge 1 commit into
sonic-net:masterfrom
xq9mend:fix/ipprefix-isvalid-const
Open

fix: mark IpPrefix::isValid() as const#1213
xq9mend wants to merge 1 commit into
sonic-net:masterfrom
xq9mend:fix/ipprefix-isvalid-const

Conversation

@xq9mend

@xq9mend xq9mend commented Jun 20, 2026

Copy link
Copy Markdown

Why

IpPrefix::isValid() only reads m_ip and m_mask — it does not modify any member. Without const, it cannot be called on const IpPrefix objects or const IpPrefix& references, making it unusable in const-correct contexts despite all other observer methods (to_string, isV4, getIp, etc.) already being correctly marked const.

How

Add const to the declaration in ipprefix.h and the definition in ipprefix.cpp.

How to verify

Existing unit tests pass. Additionally, the following now compiles correctly:

const IpPrefix p("192.168.1.0/24");
p.isValid(); // previously would not compile

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@xq9mend
xq9mend force-pushed the fix/ipprefix-isvalid-const branch from 2de76eb to 68fd86c Compare June 20, 2026 07:03
@xq9mend

xq9mend commented Jun 20, 2026

Copy link
Copy Markdown
Author

/azpw run Azure.sonic-swss-common

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@mssonicbld

Copy link
Copy Markdown
Collaborator

No Azure DevOps builds found for #1213.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

@xq9mend

xq9mend commented Jun 20, 2026

Copy link
Copy Markdown
Author

/azpw run Azure.sonic-swss-common

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1144008:

✅Stage Test:

  • Job vstest: retried.

@xq9mend

xq9mend commented Jun 21, 2026

Copy link
Copy Markdown
Author

/azpw run Azure.sonic-swss-common

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1144008:

✅Stage Test:

  • Job vstest: retried.

@xq9mend
xq9mend force-pushed the fix/ipprefix-isvalid-const branch from 68fd86c to fac5314 Compare June 21, 2026 13:41
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@xq9mend
xq9mend force-pushed the fix/ipprefix-isvalid-const branch from fac5314 to d1780c5 Compare June 21, 2026 14:41
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@xq9mend

xq9mend commented Jul 4, 2026

Copy link
Copy Markdown
Author

/azp run Azure.sonic-swss-common

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 1213 in repo sonic-net/sonic-swss-common

isValid() only reads m_ip and m_mask — it does not modify any member.
Without const, it cannot be called on const IpPrefix objects or const
references, making the method unusable in const-correct contexts.

Also fix a race condition in LruDedupPolicyConstructorAndLabelPropagation:
the drain loop was stopping at the first pops(), but the second Redis
message may not have been consumed by readData() yet. Loop until
stats.received >= 2 so the assertion is deterministic.

Signed-off-by: xq9mend <xq9mend@users.noreply.github.com>
@xq9mend
xq9mend force-pushed the fix/ipprefix-isvalid-const branch from d1780c5 to 7a28830 Compare July 8, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants